import { list, detail } from '../../api/hmmm/questions'
import { simple } from '../../api/hmmm/subjects'
import { simple as Dsimple } from '../../api/hmmm/directorys'
import { simple as Tsimple } from '../../api/hmmm/tags'
import { simple as Usimple } from '../../api/base/users'
const Questions = {
  namespaced: true,
  state: {
    total: 0,
    questionsList: [],
    simpleSubjectsList: [],
    simpleDirectoryList: [],
    simpleTagsList: [],
    simpleUsersList: [],
    questionInfo: {}
  },
  mutations: {
    setTotal (state, payload) {
      state.total = payload
    },
    setQuestionsList (state, payload) {
      state.questionsList = payload
    },
    setSimpleSubjectsList (state, payload) {
      state.simpleSubjectsList = payload
    },
    setSimpleDirectoryList (state, payload) {
      state.simpleDirectoryList = payload
    },
    setSimpleTagsList (state, payload) {
      state.simpleTagsList = payload
    },
    setSimpleUsersList (state, payload) {
      state.simpleUsersList = payload
    },
    setQuestionInfo (state, payload) {
      state.questionInfo = payload
    }
  },
  actions: {
    async getQuestionsList ({ commit }, payload) {
      const res = await list(payload)
      console.log(res)
      commit('setTotal', res.data.counts)
      commit('setQuestionsList', res.data.items)
    },
    async getSimpleSubjectsList ({ commit }, payload) {
      const res = await simple(payload)
      console.log(res.data)
      commit('setSimpleSubjectsList', res.data)
    },
    async getSimpleDirectoryList ({ commit }, payload) {
      const res = await Dsimple(payload)
      console.log(res.data)
      commit('setSimpleDirectoryList', res.data)
    },
    async getSimpleTagsList ({ commit }, payload) {
      const res = await Tsimple(payload)
      console.log(res.data)
      commit('setSimpleTagsList', res.data)
    },
    async getSimpleUsersList ({ commit }, payload) {
      const res = await Usimple(payload)
      console.log(res.data)
      commit('setSimpleUsersList', res.data)
    },
    async getQuestionInfo ({ commit }, payload) {
      const res = await detail(payload)
      console.log(res.data)
      commit('setQuestionInfo', res.data)
    }
  }
}
export default Questions
